//== SAGITTARIUS ============================================================================

//== BEGINNING OF CODE ===============================================================

#include "sagittarius/core/SagittariusCore.h"
#include "sagittarius/hash/hash.h"

#include "sagittarius/hash/MurmurHash3.h"

using namespace Sagittarius;

extern "C" {
    
uint64 sg_hashptr(void* p) {
    #if SG_PTR_SIZE == 8
        //uint64 key[2];
        uint64 val[2];
        //key[0] = (intptr_t)p;
        //key[1] = 0;
        //use some "random" seed
        MurmurHash3_x64_128(&p, 8, 0x55557777, val);
        return val[0];
    #elif SG_PTR_SIZE == 4
        //uint32 key[2];
        uint32 val[2];
        //key[0] = (intptr_t)p;
        //key[1] = 0;
        MurmurHash3_x86_32(&p, 4, 0x55557777, val);
        return val[0];
    #endif
}

uint64 sg_hash64(void* p, size_t bytes) {
    uint64 val[2];
    
    MurmurHash3_x64_128(p, bytes, 0x55557777, val);
    
    return val[0];
}

#if SAGITTARIUS_LINK_WITH_GMP
uint64 sg_hash_mpz(mpz_t p) {
    uint64 val[2];
    char str[128] = {0};
    mpz_get_str(str, 16, p);
    MurmurHash3_x64_128(str, 128, 0x55557777, val);
    return val[0];
}
#endif

} //extern "C"